package com.huluobo.h3kotlinproject.login

import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.huluobo.h3kotlinproject.net.Const
import com.huluobo.h3kotlinproject.data.UserBeanResult
import com.huluobo.h3kotlinproject.base.BaseViewModel
import okhttp3.MediaType
import okhttp3.RequestBody

/**
 *  Created by LC on 2023/10/17.
 */
class LoginViewModel() : BaseViewModel() {

    val loginSuccess: MutableLiveData<UserBeanResult> = MutableLiveData()
    val loginFailed: MutableLiveData<String> = MutableLiveData()

    fun login(username: String, password: String) {
        val map = mutableMapOf<String, String>()
        map[Const.PARAM_USERNAME] = username
        map[Const.PARAM_PASSWORD] = password
        val json = Gson().toJson(map)
        val body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json)
        val repo = LoginRepo()
        repo.login(body, loginSuccess, loginFailed)
    }
}
